﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YJKRevitStructModel.Data;

namespace YJKRevitStructModel.Kit
{
	internal class DeductionKit
	{
		public static bool DeductionWallAndColumn(Autodesk.Revit.DB.Document doc, Dictionary<ElementDataPack, List<ElementDataPack>> dicDeductionWall, Dictionary<ElementDataPack, List<ElementDataPack>> dicDeductionColumn)
		{
			Transaction transaction = new Transaction(doc, "模型扣减");
			transaction.Start();
			try
			{
				if (dicDeductionWall.Count == 0 && dicDeductionColumn.Count == 0)
				{
					YJKMessageBox.Show("没有可以进行扣减的构件");
					transaction.RollBack();
					return true;
				}
				if (!new DeductionColumn(doc, dicDeductionColumn).run())
				{
					transaction.RollBack();
					YJKMessageBox.Show("扣减构件执行错误");
					return false;
				}
				DeductionWall deductionWall = new DeductionWall(doc, dicDeductionWall);
				if (!deductionWall.Run())
				{
					transaction.RollBack();
					YJKMessageBox.Show("扣减构件执行错误");
					return false;
				}
				int numEqual = deductionWall.NumEqual;
                if ((int)transaction.Commit() != 3)
				{
					YJKMessageBox.Show("扣减构件执行错误");
					return false;
				}
				int num = dicDeductionColumn.Count + dicDeductionWall.Count;
				YJKMessageBox.Show(string.Format("共对模型中{0}个构件进行了扣减\r\n 完全重合构件{1}个 \r\n 不完全重合构件{2}个", num, dicDeductionColumn.Count + numEqual, dicDeductionWall.Count - numEqual));
			}
			catch (Exception)
			{
				transaction.RollBack();
				return false;
			}
			return true;
		}
	}
}
